"""Build security library"""


def scons():
    """Execute build"""
    Import('env', 'prereqs', 'libdaos_tgts')

    env.AppendUnique(LIBPATH=[Dir('.')])
    denv = env.Clone()

    denv.require('protobufc')

    sec_obj = denv.SharedObject('cli_security.c')
    auth_obj = denv.SharedObject('auth.pb-c.c')
    acl_obj = denv.SharedObject('acl.c')

    # dc_security: Security Client
    dc_security_tgts = [sec_obj, auth_obj, acl_obj]
    libdaos_tgts.extend(dc_security_tgts)

    senv = denv.Clone()
    senv.require("argobots")
    senv.AppendUnique(LIBS=['gurt'])
    srv_acl_obj = senv.SharedObject('srv_acl.c')
    if prereqs.server_requested():
        ds_sec = senv.d_library('security', ['srv.c', srv_acl_obj, acl_obj], install_off="../..")
        senv.Install('$PREFIX/lib64/daos_srv', ds_sec)

    # pylint: disable-next=unused-variable
    acl_tgts = [auth_obj, srv_acl_obj, acl_obj]

    dc_sectest_tgts = [srv_acl_obj, acl_obj, sec_obj, auth_obj]
    Export('dc_sectest_tgts')

    if prereqs.test_requested():
        denv = senv
        SConscript('tests/SConscript', exports=['denv', 'dc_security_tgts', 'acl_tgts'])


if __name__ == "SCons.Script":
    scons()
